﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using YunSpace.Application.SiteMgr;
using YunSpace.Core;
using YunSpace.Domain.Entity.MiniSite;
using YunSpace.Domain.Entity.SiteMgr;

namespace YunSpace.Web.Areas.MyTask.Controllers
{
    public class MyCustomerInfoController : ControllerBase
    {
        //
        // GET: /MyTask/MyCustomerInfo/
        SiteClientsApp siteApp = new SiteClientsApp();

        [HttpGet]
        [HandlerAuthorize]
        public virtual ActionResult Project()
        {
            return View();
        }

        [HttpGet]
        [HandlerAuthorize]
        public virtual ActionResult ProjectDetails()
        {
            return View();
        }

        [HttpGet]
        [HandlerAuthorize]
        public virtual ActionResult ProjectForm()
        {
            return View();
        }

        [HttpGet]
        public ActionResult GetGridDataJson(Pagination pagination)
        {
            var LoginInfo = OperatorProvider.Provider.GetCurrent();
            var data = new
            {
                //rows = siteApp.GetList(pagination, LoginInfo.UserId),
                //total = pagination.total,
                //page = pagination.page,
                //records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        public ActionResult GetIndustryRecord(Pagination pagination, string queryJson) {
            var LoginInfo = OperatorProvider.Provider.GetCurrent();
            var data = new
            {
                rows = siteApp.GetIndustryRecord(pagination, queryJson, LoginInfo.UserId),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }        

        [HttpGet]
        public ActionResult GetClientHistoryRecord(Pagination pagination, string queryJson) {
            var LoginInfo = OperatorProvider.Provider.GetCurrent();
            var data = new {
                rows = siteApp.GetClientHistoryRecord(pagination, queryJson, LoginInfo.UserId),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        public ActionResult GetItemListJson() {
            var data = new {
                citys = siteApp.GetItemList("city"),
                khdjs = siteApp.GetItemList("khdj"),
                khlxs=siteApp.GetItemList("khlx"),
                sshys=siteApp.GetItemList("sshy"),
                ssbms = siteApp.GetItemList("bmmc"),
                gszws =siteApp.GetItemList("gszw"),
                ActivityType=siteApp.GetItemList("ActivityType"),
                SiteType = siteApp.GetItemList("SiteType"),
            };
            return Content(data.ToJson());
        }

        /// <summary>
        /// 提交表单
        /// </summary>
        /// <param name="siteEntity">表单实体</param>
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitForm(Domain.Entity.MiniSite.SiteClientsEntity siteEntity, string keyValue)
        {
            //siteApp.SubmitForm(siteEntity, keyValue);
            return Success("操作成功。");
        }

        /// 提交表单
        /// </summary>
        /// <param name="siteEntity">表单实体</param>
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitProjectForm(SiteClientsProjectEntity siteEntity, string F_ClientId, string keyValue)
        {
            if (!F_ClientId.IsEmpty()) { siteEntity.F_ClientId = F_ClientId; }            
            siteApp.SubmitProjectForm(siteEntity, keyValue);
            return Success("操作成功。");
        }

        [HttpGet]
        public ActionResult GetEntity(string keyValue)
        {
            //var data = null; //siteApp.GetEntity(keyValue);
            return Content("");
        }

        [HttpGet]
        public ActionResult GetProjectEntity(string keyValue)
        {
            var data = siteApp.GetProjectEntity(keyValue);
            return Content(data.ToJson());
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [HandlerAuthorize]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteEntity(string keyValue) {
            //siteApp.DeleteEntity(keyValue);
            return Success("操作成功。");
        }

        [HttpPost]
        [HandlerAjaxOnly]
        public ActionResult DeleteProjectEntity(string keyValue)
        {
            siteApp.DeleteProjectEntity(keyValue);
            return Success("操作成功。");
        }
    }
}
